<template lang="">
  <div>
    <div class="block wow slideInLeft">
      <!-- 面包屑 -->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>技术博文</el-breadcrumb-item>
        <el-breadcrumb-item>博文详情</el-breadcrumb-item>
      </el-breadcrumb>
      <!-- 文章 -->
      <article-contents class="wow slideInLeft" :data='data'></article-contents>
      <!-- 点赞/打赏 -->
      <div class="likeBox">
        <el-button type="primary" round @click="iSclick&&like()"><i
            class="iconfont My-new-icondianzan"></i>点赞（{{data.like_count}}）
        </el-button>
        <el-button type="success" round><i class="iconfont My-new-icondashang"></i>打赏
        </el-button>
      </div>
      <!-- 评论 -->
      <comment :articleId="$route.params.id"></comment>
    </div>

  </div>
</template>
<script>
    import WOW from 'wowjs';
    //导入文章详情
    import ArticleContents from '@/components/article/article_details.vue'
    import Cookie from 'js-cookie'
    import comment from '@/components/comment.vue'
    export default {
        data() {
            return {
                //文章数据
                data: {},
                iSclick: true

            }
        },
        components: {
            ArticleContents,
            comment
        },
        methods: {
            //获取详情
            GetArticleDetail() {
                this.$axios.get('/detail', {
                    params: {
                        article_id: this.$route.params.id
                    }
                }).then(res => {

                    if (res.data.state == 200) {
                        this.data = res.data.data
                    } else {
                        this.$message.error(res.data.data);
                    }
                })
            },
            //点赞
            like() {
                // 判断是否登录了
                if (sessionStorage.getItem('token')) {
                    this.$axios.post('/like', {
                        article_id: this.$route.params.id
                    }).then(res => {
                        console.log(res.data);
                        if (res.data.code == 0) {
                            this.data.like_count = res.data.data.like_count;

                            layer.msg(res.data.msg, {
                                icon: 1,
                                time: 2000
                            })
                            this.iSclick = false

                        }

                    })
                } else {
                    this.$message({
                        message: '请登录后进行操作',
                        type: 'warning'
                    });
                    this.$router.push({
                        name: 'login'
                    })
                }

            }
        },
        mounted() {
            this.GetArticleDetail()
            let wow = new WOW.WOW({
                boxClass: 'wow',
                animateClass: 'animated',
                offset: 0,
                mobile: true,
                live: true
            });
            wow.init();
        }

    }
</script>
<style lang="less">
    .head {
        margin-top: 20px;
    }
    
    .likeBox {
        display: flex;
        justify-content: center;
        margin: 25px 0;
        .el-button {
            margin: 0 10px;
        }
        i {
            margin-right: 8px;
        }
    }
    
    .wx {
        width: 150px;
    }
</style>